#pragma once
#include "afxcmn.h"


// CConnectionInfoWindow dialog
#include "ServerSystem/ServerSystem.h"

#include <vector>

class CConnectionInfoWindow : public CDialog
{
    friend class CExamServerDlg;
    DECLARE_DYNAMIC(CConnectionInfoWindow)

public:
    CConnectionInfoWindow(CWnd* pParent = NULL);   // standard constructor
    virtual ~CConnectionInfoWindow();

// Dialog Data
    enum { IDD = IDD_ConnectionInfoWnd };

public:
    void PrepareToExit(void);

protected:
    CTreeCtrl m_treeConnections;
    HTREEITEM m_statusBranch;
    HTREEITEM m_subserverBranch;
    HTREEITEM m_clientBranch;

    HTREEITEM m_statusRootServer;
    HTREEITEM m_statusConnections;
    HTREEITEM m_statusCurrentState;
    HTREEITEM m_statusListening;
    HTREEITEM m_statusRestTime;
    HTREEITEM m_statusEndTime;
    HTREEITEM m_statusStartTime;

    typedef struct ServerInfo
    {
        HTREEITEM serverItem;
        std::vector<HTREEITEM> clients;
        std::vector<ServerInfo> clientServers;
    } ServerInfo;
    ServerInfo m_serverInfo;

protected:
    // event handlers
    void OnServerConnectionConnected(const void *pSender, ExamSystem::Server::CServerSystem *const&);
    void OnServerConnectionDisconnected(const void *pSender, ExamSystem::Server::CServerSystem *const&);
    void OnServerConnectionClosed(const void *pSender, ExamSystem::Server::CServerSystem *const&);

    void OnClientServerConnected(const void *pSender, const int&);
    void OnClientServerInfoUpdated(const void *pSender, const int&);
    void OnClientServerDisconnected(const void *pSender, const int&);

    void OnStartListening(const void *pSender, Poco::UInt16&);
    void OnExamStart(const void *, const int &);
    void OnExamStop(const void *, const int &);

    void OnClientConnected(const void *pSender, const int&);
    void OnClientDisconnected(const void *pSender, const int&);

    void OnClientServerConnectedInfo(const void *pSender, std::vector<int> &path);
    void OnClientServerDisconnectedInfo(const void *pSender, std::vector<int> &path);
    void OnClientConnectedInfo(const void *pSender, std::vector<int> &path);
    void OnClientDisconnectedInfo(const void *pSender, std::vector<int> &path);

    void OnStudentLogin(const void *pSender, const int&);

    void UpdateConnectionStatus(void);

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()

    virtual void OnOK();
    virtual void OnCancel();

public:
    afx_msg void OnSize(UINT nType, int cx, int cy);
    virtual BOOL OnInitDialog();
    afx_msg void OnTvnSelchangedTreeConnections(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnTvnGetInfoTipTreeConnections(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnDestroy();
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
};
